////                       .::::.
////                     .::::::::.
////                    :::::::::::
////                 ..:::::::::::'
////              '::::::::::::'
////                .::::::::::
////           '::::::::::::::..
////                ..::::::::::::.
////              ``::::::::::::::::
////               ::::``:::::::::'        .:::.
////              ::::'   ':::::'       .::::::::.
////            .::::'      ::::     .:::::::'::::.
////           .:::'       :::::  .:::::::::' ':::::.
////          .::'        :::::.:::::::::'      ':::::.
////         .::'         ::::::::::::::'         ``::::.
////     ...:::           ::::::::::::'              ``::.
////    ```` ':.          ':::::::::'                  ::::..
////                       '.:::::'                    ':'````..
//package com.xw.service.tool.oos;
//
//import com.amazonaws.AmazonClientException;
//import com.amazonaws.AmazonServiceException;
//import com.amazonaws.auth.PropertiesCredentials;
//import com.amazonaws.regions.Region;
//import com.amazonaws.regions.Regions;
//import com.amazonaws.services.s3.AmazonS3;
//import com.amazonaws.services.s3.AmazonS3Client;
//import com.amazonaws.services.s3.model.PutObjectRequest;
//import com.amazonaws.services.s3.model.PutObjectResult;
//import com.google.common.collect.Maps;
//import com.xw.util.AppUtil;
//import com.xw.util.JsonData;
//import com.xw.util.OOSSample;
//import com.xw.util.PropertiesUtil;
//import org.apache.commons.fileupload.disk.DiskFileItem;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.multipart.MultipartFile;
//import org.springframework.web.multipart.commons.CommonsMultipartFile;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.Date;
//import java.util.Map;
//
//@Service
//@Transactional(rollbackFor = Exception.class)
//public class OosServiceImpl implements OosService {
//    /**
//     * bucket
//     */
//    private final static String BUCKETNAME=PropertiesUtil.getProperty("OOS_BUCKET");
//
//    @Override
//    public Map upload(MultipartFile file) throws IOException {
//        Map map = Maps.newHashMap();
//        String name = file.getOriginalFilename();
//        String suff = name.substring(name.lastIndexOf("."));
//        CommonsMultipartFile cf= (CommonsMultipartFile)file;
//        DiskFileItem fi = (DiskFileItem)cf.getFileItem();
//        File f = fi.getStoreLocation();
//        String fileName= AppUtil.uuid()+suff;
//        //获取连接对象
//        AmazonS3 oosClient = getOosClient();
//        try {
//
//            /* 上传一个object到bucket中 */
//
//            System.out.println("上传一个object到bucket中");
//            String b = AppUtil.dateStr(3, new Date());
//
//
//            PutObjectResult putObjectResult = oosClient.putObject(new PutObjectRequest(BUCKETNAME, fileName,f));
//            System.err.println(putObjectResult.toString());
//            String e = AppUtil.dateStr(3, new Date());
//
//            System.err.println("开始时间" + b + "   结束时间" + e);
//
//        } catch (AmazonServiceException ase) {
//
//            System.out.println("Error Message:    " + ase.getMessage());
//
//            System.out.println("HTTP Status Code: " + ase.getStatusCode());
//
//            System.out.println("OOS Error Code:   " + ase.getErrorCode());
//
//            System.out.println("Request ID:       " + ase.getRequestId());
//
//        } catch (AmazonClientException ace) {
//
//            System.out.println("Error Message: " + ace.getMessage());
//
//        }
//        return JsonData.success(fileName);
//    }
//
//
//    private AmazonS3 getOosClient() throws IOException {
//        /* 创建client,其中OOSCredentials.properties中存放着用户名和密码*/
//        AmazonS3 oos = new AmazonS3Client(new PropertiesCredentials(
//                OOSSample.class.getClassLoader()
//                        .getResourceAsStream("OOSCredentials.properties")));
////        cn-north-1
//        oos.setRegion(Region.getRegion(Regions.SA_EAST_1));
//        // 设置endpoint
//        oos.setEndpoint("http://oos-cn.ctyunapi.cn");
//        return oos;
//    }
//}
